package org.me;

import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.StringUtils;
import org.me.utils.Koneksi;

import android.app.Dialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RemoveUser extends Dialog implements android.view.View.OnClickListener {

	ContactList contactList;
	Client client;

	public RemoveUser(ContactList contactList) {
		super(contactList);
		this.contactList = contactList;
	}
	
	public RemoveUser(Client client) {
		super(client);
		this.client = client;
	}
	
	protected void onStart() {
		super.onStart();
        setContentView(R.layout.remove_contact_dialog);
        getWindow().setFlags(4, 4);
        Button set = (Button) findViewById(R.id.btnRemove);
        set.setOnClickListener(this);
        Button cancelRemove = (Button) findViewById(R.id.cancelRemove);
        cancelRemove.setOnClickListener(this);
	}
	
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnRemove:
			EditText rmv = (EditText) findViewById(R.id.textDelete);
			String server = StringUtils.parseServer(Koneksi.getInstance().getConnection().getUser());
			String delUser = rmv.getText().toString()+"@"+server;
			Roster roster = Koneksi.getInstance().getConnection().getRoster();
			try {
				roster.removeEntry(roster.getEntry(delUser));
			} catch (XMPPException e) {
				e.printStackTrace();
			}
	        dismiss();
			break;
		case R.id.cancelRemove:
			dismiss();
			break;

		default:
			dismiss();
			break;
		}
	}
	
}
